home *** CD-ROM | disk | FTP | other *** search
/ Joystick Magazine 1996 May / cd joy 71No13.iso / pc / demos / eurosoc / source / keyh.cpp < prev    next >
C/C++ Source or Header  |  1996-02-21  |  2KB  |  132 lines

  1. #include <dos.h>
  2. #include <i86.h>
  3. #include <bios.h>
  4. #include <conio.h>
  5. #include <string.h>
  6. #include "defines.h"
  7. #include "externs.h"
  8.  
  9. extern char debug;
  10. extern char on_3d;
  11. extern int counter;
  12. char return_doskey=FALSE;
  13. extern "C" int network_on;
  14.  
  15. void    (__interrupt __far *prev_int_9)();
  16.  
  17. /****************************************************************
  18. /***************************************************************/
  19.  
  20. char anykey;
  21.  
  22. void    __interrupt __far key_handler()
  23. {
  24.     static l1=0,l2=0,l3=0;        //remember last 3 codes to check for pause.
  25.     int a;
  26.     char ret_int;
  27.  
  28.     a=inp(0x60);
  29.  
  30.     l1=l2;
  31.     l2=l3;
  32.     l3=a;
  33.     if (l1==0xE1 && l2==0x1d && l3==0x45)
  34.     {
  35.         if (!network_on)
  36.         {
  37.             paused=!paused;
  38.             ret_int=1;
  39.         }
  40.     }
  41.     else
  42.     {
  43.         ret_int=0;
  44.         if (debug)                // (Prnt Scr) for debug.
  45.             if (key_togs[0x20])        // d
  46.                 ret_int=1;
  47.  
  48.         if (!on_3d)
  49.             ret_int=1;
  50.  
  51.         if (return_doskey)
  52.             ret_int=1;
  53.     }
  54.  
  55. // Ignore 0xFA...
  56.     if (a!=0xfa)
  57.     {
  58.         if (a!=0xe0)
  59.         {
  60.             if (a & 0x80)
  61.             {
  62. // key released...
  63.                 if (l2!=0xe0)            // not special header.
  64.                 {
  65.                     keys[a & 0x7f]=0;    // Normal key release!
  66.                 }
  67.                 else
  68.                 {
  69. // special...
  70.                     keys[SPECIALK+(a & 0x7f)]=0;    // Special key release!
  71.                 }
  72.             }
  73.             else
  74.             {
  75. // new key...
  76.                 anykey=TRUE;
  77.                 if (l2!=0xe0 || a!=0x2a)
  78.                 {
  79. // no special pre-codes...
  80.                     if (l2==0xe0)
  81.                     {
  82.                         if (!keys[SPECIALK+a])
  83.                         {
  84. // new special...
  85.                             keys[SPECIALK+a]=1;    // Special key release!
  86.                             key_togs[SPECIALK+a]=!key_togs[SPECIALK+a];
  87.                         }
  88.                     }
  89.                     else
  90.                     {
  91. // Normal key depress...
  92.                         if (!keys[a])
  93.                         {
  94. // New norm. key...
  95.                             keys[a]=1;
  96.                             key_togs[a]=!key_togs[a];
  97.                         }
  98.                     }
  99.                 }
  100.             }
  101.         }
  102.     }
  103.             
  104.     if (a!=0xE1)        //trash normal pause
  105.     {
  106.         if ((a & 0x7f)!=0x1d && (a & 0x7f)!=0x45)
  107.             paused=0;
  108.     }
  109.     
  110.     if (ret_int)
  111.         _chain_intr(prev_int_9);
  112.     else
  113.         {
  114.         //suspected pause - don't pass to normal key handler!
  115.         outp(0x20,32);            //terminate int
  116.         }
  117. }
  118.  
  119. void    claim_key_int(void)
  120.     {
  121.     prev_int_9=_dos_getvect(0x9);
  122.     _dos_setvect(0x9,key_handler);
  123.     memset((void *)keys,0,128);
  124.     }
  125.  
  126.  
  127. void    release_key_int(void)
  128.     {
  129.     _dos_setvect(0x9,prev_int_9);
  130.     }
  131.  
  132.